<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/iconfont.css"/>
</head>
<body>
  <header class="aui-bar aui-bar-nav" id="aui-header">
      <a class="aui-btn aui-pull-left" tapmode onclick="historyBack()">
          <span class="aui-iconfont aui-icon-left"></span>返回
      </a>
      <a class="aui-btn aui-pull-left" tapmode onclick="closeWd()">
          关闭
      </a>
      <div id="title" class="aui-title">VIP影视</div>
      <a id="play" class="aui-btn aui-pull-right" style="color:#ff5722 !important;font-weight:bold" tapmode onclick="huanxian()">
          播放
      </a>
      <a id="play" class="aui-btn aui-pull-right" tapmode onclick="jieXi()">
          换线
      </a>
  </header>
</body>
<script type="text/javascript" src="../script/api.js" ></script>
<script type="text/javascript" src="../script/common.js" ></script>
<script type="text/javascript">
    var dataurl = '';
    var dataurl2 = '';var url_title;
    var qiyiurl = '';
    var dcode = 1;
    var onoff = true;
    var jxlist='';
    var jx_url1;
    apiready = function(){
      api.parseTapmode();
        api.setScreenOrientation({
            orientation: 'auto'
        });
      var header = $api.byId('aui-header');
      $api.fixStatusBar(header);
      var headerPos = $api.offset(header);
      var body_h = $api.offset($api.dom('body')).h;
	  jx_url1 = default_url();
      jxlist=updatelist(0,function(retlist){if(retlist)jxlist=retlist;});
      api.addEventListener({
          name: 'keyback'
      }, function(ret, err) {
        api.hideProgress();
        historyBack();
      });
      var browser = api.require('webBrowser');
      browser.openView({
          url: api.pageParam.url,
          rect: {
              x: 0,
              y: headerPos.h,
              w: 'auto',
              h: 'auto'
          }
      }, function(ret, err) {
          switch (ret.state) {//加载状态，数字类型，取值范围：0-开始加载；1-加载进度发生变化；2-结束加载；3-title发生变化；4-url发生变化
              case 0:
               dataurl = ret.url;
               dataurl2 = dataurl;
                  break;
              case 1:
                  break;
              case 2:
              cachelist(ret.url,url_title);
                  break;
              case 3:
              var title = $api.byId('title');
              url_title = ret.title;
              //title.innerHTML = 'VIP影视';
                  break;
              case 4:
                  break;
              default:
              var title = $api.byId('title');
              //title.innerHTML = 'VIP影视';
                  break;
          };
      });
    }
    function getCaption(obj){
      var index=obj.lastIndexOf("\=");
      obj=obj.substring(index+1,obj.length);
      return obj;
    }
  function historyBack(){
        var browser = api.require('webBrowser');
        browser.historyBack(
          function(ret, err) {
              if (!ret.status) {
                  api.closeWin();
              }
          }
        );
  }
 function closeWd(){
      api.closeWin({
      });
  }
    function jieXi(){
        var apilist = is_empty(jxlist)?[jx_url1]:JSON.parse(JSON.stringify(jxlist));
        var buttons=[];
        for(var i in apilist){
            var num = parseInt(i)+1;
            buttons.push('VIP线路'+num);
        }
		apilist.push('yuan');buttons.push('原网址浏览器打开');
		apilist.push('vip');buttons.push('vip网址系统浏览器打开');
      api.actionSheet({
          title: 'VIP影视VIP线路',
          cancelTitle: '取消',
          buttons: buttons
      }, function(ret, err) {
          var index = ret.buttonIndex;
          var jx_url = apilist[(index-1)];
          if(jx_url)vipHuanxian(jx_url)
      });
    }
    function huanxian(){
        api.showProgress({
          title: 'VIP解析中...',
          modal: false
      });
      setTimeout("vipHuanxian();",1500);
    }
    function getParam(name) {
        return dataurl2.match(new RegExp('[?&]' + name + '=([^?&]+)', 'i')) ? decodeURIComponent(RegExp.$1) : '';
    }
    function vipHuanxian(jiekou){
      api.hideProgress();
	  var is_browser = 0;if(jiekou=='vip' || jiekou=='yuan')is_browser = 1;
        if(!jiekou || jiekou=='vip')jiekou=jx_url1;
		var vipurl = jiekou+encodeURIComponent(dataurl2);
		if(jiekou=='yuan')vipurl = dataurl2;
		if(is_browser){
			api.openApp({
			 iosUrl: vipurl,
			 androidPkg: 'android.intent.action.VIEW',
			 uri: vipurl
		}, function (ret, err) {
		});return ;
		}
      var systemType = api.systemType;
      if (systemType == 'android') {
        api.openWin({
            name: 'play_win',
            url: './play_win.html',
            delay: 300,
            pageParam:{url:vipurl},
            bgColor: '#000000'
        });
      }else {
        var browser = api.require('webBrowser');
        browser.open({
            url: jiekou+dataurl2,
            titleBar: {
              visible: true
            }
        });
      }
    }
</script>
</html>